﻿//-----------------------------------------------------------------------
// <copyright file="AlertCommand.cs">
//     Copyright © 2010. All rights reserved.
// </copyright>
// <author>Lakshman Peethani</author>
//-----------------------------------------------------------------------
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PhoneGap;

namespace PhoneGap.Plugins.Notification
{
    public class ConfirmCommand : PhoneGapCommand, IAsyncCommand
    {
        public override void Execute(params string[] args)
        {
            var caption = string.Empty;

            if (args.Length >= 2)
            {
                caption = args[2];
            }

            MessageBoxResult result  = MessageBox.Show(args[0], caption, MessageBoxButton.OKCancel);
            this.CallbackArgs = new string[]{(result== MessageBoxResult.OK?"OK":"Cancel")};
            this.CallbackName = args[1];
            //this.HasCallback = true;
            this.SendAsyncResponse();
        }

        public void SendAsyncResponse()
        {
            if (this.OnCommandCompleted != null)
            {
                this.OnCommandCompleted(null, this);
                this.OnCommandCompleted = null;
            }
        }

        public event EventHandler<PhoneGapCommand> OnCommandCompleted;
    }
}
